#include<iostream>
using namespace std;
bool bubblesort(int a[],int n)
{
 if (n < 0)
 {
  return  false;
 }
 if (n == 1)
 {
  return true;
 }
 int tmp;
 for (int i = 0; i < n; i++)  
 {
  bool isExchanged = false;
  for (int j = 0; j < n-i-1; j++) 
  {
   if (a[j] > a[j+1])
   {
   
    tmp = a[j];
    a[j] = a[j+1];
    a[j+1] = tmp;
    isExchanged = true;
   }
  }
  if (!isExchanged)
  {
   return true;
   break;
  }
 }
 return true;
}

int main()
{
 int a[5] = { 4,2,1,3,5 };
 if (bubblesort(a, 5))
 {
  for (int i = 0; i < 5; i++)
  {
   cout << a[i] << " ";
  }
 }
 
 return 0;
}